<div class="panel panel-default panel-intro">
    <div class="panel-heading">
        {:build_heading(null, false)}
        <ul class="nav nav-tabs">
            {volist name="cates" id="vo"}
             <li {if condition="( (!empty($data)) AND ($data['cate'] eq $vo['id']) ) OR ( (!empty($cate_name)) AND  ($cate_name eq $vo['name']) ) OR ( empty($data) AND empty($cate_name) AND ($key eq 0))"} class="active" {/if}><a href="#type_{$vo.id}" data-toggle="tab">{$vo.name}</a></li>
            {/volist}
        </ul>
    </div>
    <div class="panel-body">
        <div id="myTabContent" class="tab-content">
            {volist name="cates" id="vo"}
             <div class="tab-pane fade {if condition=" ( (!empty($data)) AND ($data['cate'] eq $vo['id']) ) OR ( (!empty($cate_name)) AND  ($cate_name eq $vo['name']) ) OR ( empty($data) AND empty($cate_name) AND ($key eq 0))"} active in {/if}" id="type_{$vo.id}">
                <form id="type_{$vo.id}_form" class="form-horizontal" role="form" action="{:url('zsave')}"  method="POST">
                    <div class="form-group">
                        <label class="control-label col-xs-12 col-sm-2">资源类型:</label>
                        <div class="col-xs-12 col-sm-8">
                            <select class="form-control" name="cate">
                                <option value="{$vo['id']}" selected >{$vo.name}</option>
                            </select>
                        </div>
                    </div>
                 {switch name="vo['name']" }
                   {case value="功能资源"}
                     <div class="form-group">
                        <label class="control-label col-xs-12 col-sm-2">模块:</label>
                        <div class="col-xs-12 col-sm-8">
                            <select class="form-control" name="model" >
                                <option value="0">请选择</option>
                                {volist name="models" id="model"}
                                <option value="{$model['id']}" {if condition="((!empty($data)) AND $model['id'] eq $data['model']) OR ((!empty($gongnen)) AND $model['id'] eq $gongnen['model_id'])"}selected{/if}>{$model.name}</option>
                                {/volist}
                            </select>
                        </div>
                    </div>
                     <div class="form-group">
                        <label class="control-label col-xs-12 col-sm-2">功能:</label>
                        <div class="col-xs-12 col-sm-8">
                            <select class="form-control" name="gongnen">
                                <option value="0">请选择</option>
                                {volist name="gongnens" id="go"}
                                <option value="{$go['id']}" {if condition="((!empty($data)) AND $go['id'] eq $data['gongnen']) OR ((!empty($gongnen)) AND $go['id'] eq $gongnen['id'])"}selected{/if}>{$go.name}</option>
                                {/volist}
                            </select>
                        </div>
                    </div>
                     <div class="form-group">
                        <label class="control-label col-xs-12 col-sm-2">功能清单:</label>
                        <div class="col-xs-12 col-sm-8">
                            <select class="form-control" name="child_gongnen">
                                <option value="">请选择</option>
                                {volist name="child_gongens" id="ch"}
                                <option value="{$go['id']}" {if condition="((!empty($data)) AND $ch['id'] eq $data['child_gongnen']) OR ((!empty($gongnen)) AND $ch['id'] eq $gongnen['cid'])"}selected{/if}>{$ch.cname}</option>
                                {/volist}
                            </select>
                        </div>
                    </div>
                   {/case}
                   {case value="模块资源"}
                       <div class="form-group">
                        <label class="control-label col-xs-12 col-sm-2">模块:</label>
                        <div class="col-xs-12 col-sm-8">
                            <select class="form-control" name="model" >
                                <option value="0">请选择</option>
                                {volist name="models" id="ch"}
                                <option value="{$ch['id']}" {if condition="((!empty($data)) AND $ch['id'] eq $data['model']) OR ((!empty($model)) AND $ch['id'] eq $model['id'])"}selected{/if}>{$ch.name}</option>
                                {/volist}
                            </select>
                        </div>
                    </div>
                    {/case}

                    {case value="页面资源"}

                     <div class="form-group">
                        <label class="control-label col-xs-12 col-sm-2">板块:</label>
                        <div class="col-xs-12 col-sm-8">
                            <select class="form-control" name="plate" id="plate">
                                <option value="0">请选择</option>
                                {volist name="plates" id="ch"}
                                 <option value="{$ch['id']}" {if condition="((!empty($data)) AND $ch['id'] eq $data['plate'])  OR ((!empty($page)) AND $ch['id'] eq $page['p_id'])"}selected{/if}>{$ch.name}</option>
                                  {volist name="ch['son']" id="son"}
                                    <option value="{$son.id}" {if condition="((!empty($data)) AND $son['id'] eq $data['plate']) OR ((!empty($page)) AND $son['id'] eq $page['p_id'])"}selected{/if}>---{$son.name}</option>
                                  {/volist}
                                {/volist}
                            </select>
                        </div>
                    </div>

                     <div class="form-group">
                        <label class="control-label col-xs-12 col-sm-2">页面:</label>
                        <div class="col-xs-12 col-sm-8">
                            <select class="form-control" name="page" id="page">
                                <option value="0">请选择</option>
                                {volist name="pages" id="ch"}
                                 <option value="{$ch['id']}" {if condition="((!empty($data)) AND $ch['id'] eq $data['page']) OR ((!empty($page)) AND $ch['id'] eq $page['id'])"}selected{/if}>{$ch.name}</option>
                                {/volist}
                            </select>
                        </div>
                    </div>
                    {/case}

                    {case value="板块资源"}
                      <div class="form-group">
                        <label class="control-label col-xs-12 col-sm-2">板块:</label>
                        <div class="col-xs-12 col-sm-8">
                            <select class="form-control" name="plate">
                                <option value="0">请选择</option>
                                {volist name="plates" id="ch"}
                                <option value="{$ch['id']}" {if condition="(!empty($data)) AND $model['id'] eq $data['plate']"}selected{/if}>{$ch.name}</option>
                                {/volist}
                            </select>
                        </div>
                     </div>
                    {/case}
                {/switch}



                    <div class="form-group">
                        <label class="control-label col-xs-12 col-sm-2">格式:</label>
                        <div class="col-xs-12 col-sm-8">
                            <label style="font-weight: normal;margin-right: 15px;cursor: pointer;"><input style="position: relative;top: 2px;" type="radio" name="type" value="1" {if condition="((!empty($data)) AND $data['type'] == 1) OR (empty($data))"}checked{/if}>图片</label>
                            <label style="font-weight: normal;margin-right: 15px;cursor: pointer;"><input style="position: relative;top: 2px;" type="radio" name="type" value="2" {if condition="(!empty($data)) AND $data['type'] == 2"}checked{/if}>代码</label>
                            <label style="font-weight: normal;margin-right: 15px;cursor: pointer;"><input style="position: relative;top: 2px;" type="radio" name="type" value="3" {if condition="(!empty($data)) AND $data['type'] == 3"}checked{/if}>其他</label>
                        </div>
                    </div>
                    <div class="form-group ss attr attr_1">
                        <label class="control-label col-xs-12 col-sm-2">属性:</label>
                        <div class="col-xs-12 col-sm-8">
                            {volist name="attr['gnt']" id="ch"}
                              <label style="font-weight: normal;margin-right: 15px;cursor: pointer;" class="gnt"><input style="position: relative;top: 3px;" type="radio" name="attr" {if condition="(!empty($data)) AND $data['attr'] == $ch['id']"}checked{/if}  value="{$ch.id}">{$ch.name}</label>
                            {/volist}
                        </div>
                    </div>

                    <div class="form-group ss attr attr_2" style="display: none;">
                        <label class="control-label col-xs-12 col-sm-2">属性:</label>
                        <div class="col-xs-12 col-sm-8">
                            {volist name="attr['dm']" id="ch"}
                              <label style="font-weight: normal;margin-right: 15px;cursor: pointer;" class="dm"><input style="position: relative;top: 3px;" type="radio" name="attr" {if condition="((!empty($data)) AND $data['attr'] == $ch['id']) OR ($key eq 0)"}checked{/if} value="{$ch.id}" data-name="{$ch.name}">{$ch.name}</label>
                            {/volist}
                        </div>
                    </div>

                     <div class="form-group qita attr attr_3" style="display: none;">
                        <label class="control-label col-xs-12 col-sm-2">其他:</label>
                        <div class="col-xs-12 col-sm-8">
                            <input type="text" name="attr" value="{$data['attr']|default=''}" class="form-control"/>
                        </div>
                    </div>


                    <div class="form-group yuyan qd" style="display: none">
                        <label class="control-label col-xs-12 col-sm-2">语言:</label>
                        <div class="col-xs-12 col-sm-8">
                            {volist name="language['qd']" id="ch"}
                             <label style="font-weight: normal;margin-right: 15px;cursor: pointer;" class="qd"><input style="position: relative;top: 2px;" name="language[]" value="{$ch.id}"  {if condition="(!empty($data)) AND in_array($ch['id'],$data['language'])"}checked{/if} type="checkbox">{$ch.name}</label>
                            {/volist}
                        </div>
                    </div>

                     <div class="form-group yuyan hd" style="display: none">
                        <label class="control-label col-xs-12 col-sm-2">语言:</label>
                        <div class="col-xs-12 col-sm-8">
                            {volist name="language['hd']" id="ch"}
                             <label style="font-weight: normal;margin-right: 15px;cursor: pointer;" class="hd"><input style="position: relative;top: 2px;" name="language[]" value="{$ch.id}" {if condition="(!empty($data)) AND in_array($ch['id'],$data['language'])"}checked{/if} type="checkbox">{$ch.name}</label>
                            {/volist}
                        </div>
                    </div>

                     <div class="form-group yuyan qz" style="display: none">
                        <label class="control-label col-xs-12 col-sm-2">语言:</label>
                        <div class="col-xs-12 col-sm-8">
                            {volist name="language['qd']" id="ch"}
                             <label style="font-weight: normal;margin-right: 15px;cursor: pointer;" class="qd"><input style="position: relative;top: 2px;" name="language[]" value="{$ch.id}"  {if condition="(!empty($data)) AND in_array($ch['id'],$data['language'])"}checked{/if} type="checkbox">{$ch.name}</label>
                            {/volist}

                            {volist name="language['hd']" id="ch"}
                             <label style="font-weight: normal;margin-right: 15px;cursor: pointer;" class="hd"><input style="position: relative;top: 2px;" name="language[]" value="{$ch.id}" {if condition="(!empty($data)) AND in_array($ch['id'],$data['language'])"}checked{/if} type="checkbox">{$ch.name}</label>
                            {/volist}

                        </div>
                    </div>



                 {notempty name="data.file"}
                    {volist name="data['file']" id="file"}
                     <div class="form-group resouce">
                        <label class="control-label col-xs-12 col-sm-2">上传:</label>
                        <div class="col-xs-4 col-sm-3">
                            <input type="text" class="form-control" name="path[]" value="{$file.path}" placeholder="地址" />
                        </div>
                        <div class="col-xs-4 col-sm-3">
                            <input type="text" class="form-control" name="des[]" value="{$file.des}" placeholder="描述" />
                        </div>
                        <input type="hidden" class="form-control" name="fids[]"  value="{$file.id}"  value />
                        <div class="col-xs-4 col-sm-3" style="line-height: 27px;">
                            <span class="btn btn-xs btn-danger">删除</span>
                            <span class="btn btn-xs btn-success">查看</span>
                            <span class="btn btn-xs btn-success btn-add">添加</span>
                        </div>
                    </div>
                   {/volist}

                 {else /}
                    <div class="form-group resouce">
                        <label class="control-label col-xs-12 col-sm-2"></label>
                        <div class="col-xs-4 col-sm-3">
                            <input type="text" class="form-control" name="path[]" placeholder="地址" />
                        </div>
                        <div class="col-xs-4 col-sm-3">
                            <input type="text" class="form-control" name="des[]" placeholder="描述" />

                        </div>
                        <input type="hidden" class="form-control" name="fids[]" value />
                        <div class="col-xs-4 col-sm-3" style="line-height: 27px;">
                            <span class="btn btn-xs btn-danger">删除</span>
                            <span class="btn btn-xs btn-success">查看</span>
                            <span class="btn btn-xs btn-success btn-add">添加</span>
                        </div>
                    </div>
                {/notempty}

                    <div class="form-group" id="container_{$vo['id']}>
                        <label class="control-label col-xs-12 col-sm-2"></label>
                        <div class="col-xs-12 col-sm-8" style="text-align: center;">
                            
                            <span class="btn btn-xs btn-success btn-add" id="upload_good_img_{$vo['id']}">选择图片</span>
                             <span class="btn btn-xs btn-success" id="uploadfiles_{$vo['id']}">开始上传</span>
                            <script type="text/javascript">
                                //上传图片\
                                var id="{$vo['id']}";
                               /* function uploadPicture(file, data) {
                                    var data = eval('('+data+')');
                                    var src = '';
                                    if (data.code) {
                                        src = data.url;
                                        $("input[name='path[]']").each(function(){
                                            if($(this).val()==''){
                                               $(this).val(src);
                                               return false;
                                             }
                                             
                                        })
                                    } else {
                                        alert(data.info);
                                    }
                                }*/

                                var browse_button="upload_good_img_"+id;
                                var uploader = new plupload.Uploader({
                                       runtimes : 'html5,flash,silverlight,html4',//上传方式顺序优先级
                                       browse_button : browse_button,//选择图片按钮id
                                       container: document.getElementById('container_'+id),//容器
                                       url : "{:url('Index/upload_images')}",//服务器接口地址
                                       flash_swf_url : "__CDN__/assets/js/plupload/Moxie.swf",
                                       silverlight_xap_url : "__CDN__/assets/js/plupload/Moxie.xap",
                                       multi_selection: true,//false为单图上传，true为多图上传
                                       filters : {
                                           max_file_size : '100mb',//限制文件上传大小
                                           mime_types: [],
                                           prevent_duplicates : true
                                       },
                                       init: {
                                           //init事件发生后触发
                                           PostInit: function() {
                                               //document.getElementById('filelist').innerHTML = '';
                                               document.getElementById('uploadfiles_'+id).onclick = function() {
                                                     uploader.start();
                                                     return false;
                                                  };
                                           },
                                           FilesAdded: function(up,files) {
                                             
                                               var len = len = files.length;
                                               for(var i = 0; i<len; i++){
                                                   var file_name = files[i].name; //文件名
                                                   var file_size = files[i].size;//文件大小
                                                   var html = '<li id="file-' + files[i].id +'"><span class="close"></span></li>';
                                                   $(html).appendTo('#file-list');
                                                    previewImage(files[i],function(imgsrc){
                                                           $('#file-'+files[i].id).append('<a><img src="'+ imgsrc +'" /><span class="progress">12</span></a>');
                                                       })
                                                   $("#uploadfiles").trigger('click');
                                               }
                                              
                                           },
                                
                                           UploadProgress: function(up, file) {
                                             
                                               $('#file-'+file.id +" .progress").html(file.percent + "%");
                                           },
                                           FileUploaded : function (up,file,res) {
                                               console.log(res.response);
                                               var data = JSON.parse(res.response).data;
                                               $('#file-'+file.id).children('.close').attr('img_id',data.img_id);
                                               var img = $("#images_upload");
                                               var str = img.val();
                                               if(str == ''){
                                                   str = data.img_id;
                                               }else{
                                                   str += ','+data.img_id;
                                               }
                                               img.val(str);
                                           },
                                           Error: function(up, err) {
                                               
                                           }
                                       }
                                   });
                                function previewImage(file,callback){
                                        if(!file || !/image\//.test(file.type)) return; //确保文件是图片
                                        if(file.type=='image/gif'){ //gif使用FileReader进行预览,因为mOxie.Image只支持jpg和png
                                            var gif = new moxie.file.FileReader();
                                            gif.onload = function(){
                                                callback(gif.result);
                                                gif.destroy();
                                                gif = null;
                                            };
                                            gif.readAsDataURL(file.getSource());
                                        }else{
                                            var image = new moxie.image.Image();
                                            image.onload = function() {
                                                image.downsize( 150, 150 );//先压缩一下要预览的图片,宽300，高300
                                                var imgsrc = image.type=='image/jpeg' ? image.getAsDataURL('image/jpeg',80) : image.getAsDataURL(); //得到图片src,实质为一个base64编码的数据
                                                callback && callback(imgsrc); //callback传入的参数为预览图片的url
                                                image.destroy();
                                                image = null;
                                            };
                                            image.load( file.getSource() );
                                        }
                                    }
                                 
                                    uploader.init();
                            </script>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="control-label col-xs-12 col-sm-2"></label>
                        <div class="col-xs-12 col-sm-8">
                            <input type="hidden" name="id" value="{$data['id']|default=''}" />
                            <button type="submit" id="submit" class="btn btn-success">{:__('OK')}</button>
                        </div>
                    </div>
                </form>
            </div>
            {/volist}

        </div>
    </div>
</div>
<script>
    $(function() {

        $("body").on("click", ".btn-danger", function () {
            $(this).parents('.resouce').remove();
        });


        $("body").on("click", ".btn-add", function () {
            var div_clone = $(this).parents('.resouce').clone(true);
            $(this).parents('.resouce').after(div_clone);
        });

        //板块切换时
        $("body").on("click", "#plate", function () {
            var plate_id = $(this).val();
            $.ajax({
                type: 'GET',
                data: {plate_id: plate_id},
                url: "{:url('ajaxGetPage')}",
                success: function (data) {
                    $("#page").html('')
                    $("#page").append(data.msg);
                }
            });

        })

        $("input[name=type]").click(function(){
            var checked=$(this).val();
            $(".attr").hide();
            $(".attr_"+checked).show();
            if(checked==2){
                $(".qd").show();
            }

        });

        $(".attr_2").find(":radio").click(function(){
           var name=$(this).attr('data-name');
            $(".yuyan").hide();
           switch(name){
             case "前端代码":
              $(".qd").show(); 
             break; 
             case "后端代码":
              $(".hd").show(); 
             break;
             case "全栈代码":
              $(".qz").show();
             break;
           }  
        })

    });

</script>

